<?php
	$page_name= $_SERVER['PHP_SELF']."?page=views";
    //echo $page_name;

if(isset($_GET['start'])){
	$start=$_GET['start'];
}else{
	$start = 0;
}

$startFrom = $start; 
$limit = 5;  // No of records to be shown per 
$currentPage = $startFrom + $limit; 

$back = $startFrom - $limit; 
$next = $startFrom + $limit; 



$queryCount=" SELECT stu_id FROM tbl_students";
$countNumRow = mysql_query($queryCount);
$nume = mysql_num_rows($countNumRow);


$query=" SELECT * FROM tbl_students stu inner join tbl_classes cla on  stu.cla_id = cla.cla_id order by stu_date_create desc limit $startFrom, $limit  ";
$result=mysql_query($query);


?>
<html>
	<head>
		
		<link href="styles/style.css" type="text/css" rel="stylesheet" />

<script type="text/javascript" language="JavaScript1.8">
		function confirmDelete()
		{
    		return confirm("Are you sure you wish to delete this entry?");
		}
		
		function changeImage(itemChang){
			//alert(itemChang.src);
			//itemChang.src = "images/icons/user-add-hover.png";
		}
		
	</script>
	</head>

<body>
	
<div id="wraper">
  <div id="sub_title"> Student Management
    <hr id="line" />
  </div>
  <div id="action_top"> 
    <!--	<img name="btn" src="images/icons/user-add.png"
onmouseover="btn.src='images/icons/user-add-hover.png';"
onmouseout="btn.src='images/icons/user-add.png';" />	--> 
    
    <a href="index.php?page=form&action=add" > <img name="image" src="images/icons/user-add.png"
onmouseover="javascript: image.src='images/icons/user-add-hover.png';"
onmouseout="javascript: image.src='images/icons/user-add.png';" /> <br />
    Add new</a> </div>
  <div>
    <table class="list" cellpadding="0" cellspacing="0" border="1">
      <tr id="table_top">
        <th >First Name</th>
        <th >Last Name</th>
        <th >Sex</th>
        <th >Telephone</th>
        <th>Email</th>
        <th>Class</th>
        <th >Photo</th>
        <th >Actions</th>
      </tr>
      
      <!--  <tr class="old">
  	<td colspan="6"> Test</td>
  </tr>-->
      
      <?php
	$i = 1;
	//$result = mysql_query("SELECT * FROM students");
	
	while ($row = mysql_fetch_array($result)){  ?>
      <tr <?php echo(($i%2)?'class=old':'class=eve'); ?>>
        <td id="firstName"><?php echo $row['stu_first_name']; ?></td>
        <td id="lastName"><?php echo $row['stu_last_name']; ?></td>
        <td width="120" align="center"><?php  echo( $row['stu_sex']== 'M'?"Male":"Female" )?></td>
        <td><?php echo $row['stu_telephone']; ?></td>
        <td><?php echo $row['stu_email']; ?></td>
        
        <td><?php echo $row['cla_name']; ?></td>
        <td align="center"><img src="uploads/thumbs/thumb_<?php echo $row['stu_photo']; ?>" title="" alt="" /></td>
        <td align="center"><pre> <a href="index.php?page=form&action=edit&id=<?php echo $row['stu_id']?>" >Edit</a> | <a href="controls/action.php?action=delete&id=<?php echo $row['stu_id']?>" onClick="javascript: return confirmDelete()">Delete</a> </pre></td>
      </tr>
      <?php
	$i++;
    }
	?>
    </table>
  </div>
</div>
<br />
<div>
  <?php
		if($nume > $limit ){ 
echo "<table align = 'center' width='50%'><tr><td  align='left' width='30%'>";

if($back >=0) { 
print "<a href='$page_name&start=$back'><font face='Verdana' size='2'>PREV</font></a>"; 
} 

echo "</td><td align=center width='30%'>";
  /*
    $link = ceil($nume/$limit);
    for($i = 1; $i<= $link;$i++){
        echo " <a href='$page_name&start=$i+$limit'><font face='Verdana' size='2'>$i</font></a> ";
        
    }
   */

$i=0;
$l=1;
for($i=0;$i < $nume;$i=$i+$limit){
if($i <> $startFrom){
echo " <a href='$page_name&start=$i'><font face='Verdana' size='2'>$l</font></a> ";
}
else { echo "<font face='Verdana' size='4' color=red>$l</font>";}       
$l++;
}

echo "</td><td  align='right' width='30%'>";

if($currentPage < $nume) { 
print "<a href='$page_name&start=$next'><font face='Verdana' size='2'>NEXT</font></a>";} 
echo "</td></tr></table>";

}
	?>
</div>
</body></html>